package cn.bocweb.spinning.view.common;

import android.os.CountDownTimer;
import android.widget.TextView;

import cn.bocweb.spinning.util.DeviceUtil;

/**
 * Created by chenchangxing on 15/11/16.
 */
public class TimeTick extends CountDownTimer {

    OnFinishListener onFinishListener;
    TextView tv;

    public long getFinishTime() {
        return finishTime;
    }

    long finishTime;

    public TimeTick(long millisInFuture, long countDownInterval, TextView tv) {
        super(millisInFuture, countDownInterval);
        this.tv = tv;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        tv.setText(DeviceUtil.getTickInfoForData(millisUntilFinished/1000));
        finishTime = millisUntilFinished;
    }

    @Override
    public void onFinish() {
        onFinishListener.onFinish(finishTime);
    }

    public interface OnFinishListener {
        void onFinish(long time);
    }

    public void setOnFinishListener(OnFinishListener onFinishListener) {
        this.onFinishListener = onFinishListener;
    }
}
